package com.client.widgets;

import java.sql.Date;

import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.DecoratorPanel;
import com.google.gwt.user.client.ui.FocusPanel;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.MouseListener;
import com.google.gwt.user.client.ui.PopupListener;
import com.google.gwt.user.client.ui.PopupPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;

public class EventWidget extends NodeWidget{
	//data
	private String time;
	private String title;
	private int day;
	private String month;
	private int year;
	private String host;
	private String room;
	private String extraInfo;
	//gui
	private FocusPanel mainPanel;
	private PopupPanel details;
	
	public EventWidget(String t, int d, String m, int y, String name, String eventHost, String eventRoom, String extra) {
		this.time = t;
		this.day = d;
		this.month = m;
		this.year = y;
		this.title = name;
		this.host = eventHost;
		this.room = eventRoom;
		this.extraInfo = extra;
		//data inits
		this.mainPanel = new FocusPanel();
		this.details = new PopupPanel();
		//gui inits and adds
		HorizontalPanel mainHPanel = new HorizontalPanel();
		this.mainPanel.add(mainHPanel);
		this.details.setAnimationEnabled(true);
		mainHPanel.add(new Label(t));
		
		//create a title label
		mainHPanel.add(new Label(name));
		
		mainHPanel.add(new Label(eventHost));
		mainHPanel.add(new Label(eventRoom));

		//create a panel of extra info
		VerticalPanel detailsVP = new VerticalPanel();
		
		
		detailsVP.add(new Label(extra));
		this.details.add(detailsVP);
		
		//add some mouse listeners
		this.mainPanel.addMouseListener(new MouseListener() {
			public void onMouseDown(Widget sender, int x, int y) {}
			public void onMouseEnter(Widget sender) {
				displayDetails();
			}
			public void onMouseLeave(Widget sender) {
				hideDetails();
			}
			public void onMouseMove(Widget sender, int x, int y) {
				moveDetails(x+1+mainPanel.getAbsoluteLeft(),y+10+mainPanel.getAbsoluteTop());
			}
			public void onMouseUp(Widget sender, int x, int y) {}	
		});
		
		DecoratorPanel decoPanel = new DecoratorPanel();
		decoPanel.add(mainPanel);
		initWidget(decoPanel);
	}
	
	private void displayDetails() {
		this.details.show();
		this.details.setPopupPosition(mainPanel.getAbsoluteLeft()+mainPanel.getOffsetWidth()/2,
				mainPanel.getAbsoluteTop()+mainPanel.getOffsetHeight()/2);
	}
	
	private void hideDetails() {
		this.details.hide();
	}
	
	private void moveDetails(int x, int y) {
		this.details.setPopupPosition(x, y);
	}
	
}
